package exam;

import exam.TreeNode;
import java.util.ArrayList;
import java.util.List;

/**
 * Tests the answer to the first tree question.
 * The text of the question is as follows:
 * "Write a method that counts the number of times a given element appears in a binary tree."
 * 
 * @author Branden Ogata
 *
 */

public class TestTreeA00 extends Tester
{
  public static void main(String[] args)
  {
    final double POINTS = getPoints(args);
    
    // Sets up the tree used in testing
    String[] values = new String[] {"b", "i", "n", "a", "r", "y", 
    		                            "t", "r", "e", "e",
                                    "d", "a", "t", "a", 
                                    "s", "t", "r", "u", "c", "t", "u", "r", "e"};
    List<TreeNode<String>> nodes = new ArrayList<TreeNode<String>>();
    
    // Create the nodes with data
    for (int i = 0; i < values.length; i++)
    {
      nodes.add(new TreeNode<String>(values[i]));
    }

    // Add in the links between nodes
    for (int i = 0; i < values.length; i++)
    {
      // If a left child exists
      if (((2 * i) + 1) < values.length)
      {
        nodes.get(i).setLeft(nodes.get((2 * i) + 1));
      }
      
      // If a right child exists
      if (((2 * i) + 2) < values.length)
      {
        nodes.get(i).setRight(nodes.get((2 * i) + 2));        
      }
    }

    System.out.println(test(Category.EQUALS, "count(TreeNode<E>, E) for element not in tree", 
                            0, TreeA00.count(nodes.get(0), "o"), 
                            percentageToPoints(THIRD, POINTS)));

    System.out.println(test(Category.EQUALS, "count(TreeNode<E>, E) for element in tree once", 
                            1, TreeA00.count(nodes.get(0), "d"), 
                            percentageToPoints(THIRD, POINTS)));

    System.out.println(test(Category.EQUALS, "count(TreeNode<E>, E) for element in tree several", 
                            4, TreeA00.count(nodes.get(0), "t"), 
                            percentageToPoints(THIRD, POINTS)));
    
    System.out.format("[%.2f/%.2f]%n", getTotalPoints(), POINTS);
  }
}
